package org.restoran.model;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.springframework.data.domain.Persistable;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property.
 *
 * @author Snisar Bogdan.
 */
@MappedSuperclass
public abstract class BaseEntity implements Serializable, Identifiable<Integer> {

    protected BaseEntity(Integer id) {
        this.id = id;
    }

    public BaseEntity() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Integer id;

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Check if this entity object new.
     *
     * @return this.getPk() == null
     */
    @JsonIgnore
    @Override
    public boolean isNew() {
        return this.getId() == null;
    }
}
